/**
 * 
 */
package org.rollinitiative.d20.items;

import java.util.ArrayList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * This class maintains a collection of items and their state with respect to carrying and
 * equipping. Weight of carried and equipped items is calculated.
 * 
 * @author bebopjmm
 * 
 */
public class Inventory
{
    final static Log LOG = LogFactory.getLog(Inventory.class);
    
    ArrayList<Item> itemList = new ArrayList<Item>();
    
    double weight = 0.0;
    
    public synchronized void addItem(Item newItem)
    {
        // Verify this item is not already part of our inventory
        if (itemList.contains(newItem)) {
            return;
        }
        
        itemList.add(newItem);
        weight += newItem.getWeight();
    }
    
    public synchronized void removeItem(Item targetItem)
    {
     // Verify this item is part of our inventory
        if (!itemList.contains(targetItem)) {
            return;
        }
        
        itemList.remove(targetItem);
        weight -= targetItem.getWeight();
    }
 
    public double getWeight()
    {
        return weight;
    }
    
    public synchronized Item[] getContents()
    {
        return itemList.toArray(new Item[itemList.size()]);
    }
}
